package com.relax.netty.socket;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

public class Client {
    public static void main(String[] args) {
        try {
            // 创建 Socket，并连接服务器
            Socket socket = new Socket("localhost", 8888);

            // 获取输入流和输出流
            BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            PrintWriter writer = new PrintWriter(socket.getOutputStream(), true);

            // 向服务器发送消息
            writer.println("Hello, Server!");

            // 读取服务器的响应数据并进行处理
            String serverMessage = reader.readLine();
            System.out.println("服务器响应：" + serverMessage);

            // 关闭连接
            socket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
